﻿<cfsilent>
	<cfscript>
		
		stringAdvice = getProperty("serviceFactory").getBean("stringAdvice");
		dateTimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		
		event.setArg("pageTitle", "学生调查问卷 - 调查问卷结果");
		
		currentTab = event.getArg("TabID", "labRecentVote");
		
		sql = "SELECT 
					 a.qsn_id, 
					 a.title, 
					 a.date_start, 
					 a.date_end, 
					 t_teacher.tch_name, 
					 (SELECT COUNT(*) FROM t_respondents b WHERE b.qsn_id = a.qsn_id AND b.state = 'S') countRes_S, 
					 (SELECT COUNT(*) FROM t_respondents c WHERE c.qsn_id = a.qsn_id) countRes  
				FROM 
					 t_questionnaire a 
					 INNER JOIN t_teacher ON t_teacher.tch_id = a.tch_id 
				WHERE 
					 
					 a.date_end < :today 
					 AND 
					 a.date_end > :start 
					 AND 
					 a.date_end < :end 
					 AND 
					 a.state = '2' 
				ORDER BY 
					 a.date_end DESC, a.title "; 
		
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="today", value=dateFormat(now(), "YYYYMMDD"), cfsqltype="cf_sql_char" );
		queryObj.addParam( name="start", value=dateFormat(now(), "YYYYMM00"), cfsqltype="cf_sql_char" );
		queryObj.addParam( name="end", value=dateFormat(now(), "YYYYMM32"), cfsqltype="cf_sql_char" );
		
		rs_questRecentMonth = queryObj.execute( sql=sql ).getResult();
		
		passArgs = structNew();
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
            <div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('DEFAULT_EVENT')#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">在线调查</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 bar"></i>调查问卷结果
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labRecentVote">class="active"</cfif> id="labRecentVote" tabTarget="RecentVote">近一个月的问卷</span>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>				
				</script>
				
				<!--- 隐藏提交 --->
				<form id="formExport" class="hidden_elem" method="post" action="<cfoutput>#buildURL('voteAnalysisBatchExportExcel')#</cfoutput>">
					<textarea id="exportQSNIDs" name="QSNIDs"></textarea>
				</form>
				
				<form id="formPrint" class="hidden_elem" method="post" action="<cfoutput>#buildURL('voteAnalysisBatchPrint')#</cfoutput>">
					<textarea id="printQSNIDs" name="QSNIDs"></textarea>
				</form>
				
				<div id="RecentVote" class="tabContent">
					
					<div class="noticeBlock">
				
						<cfif rs_questRecentMonth.recordCount>
							<div class="operation">
								<a class="uiButton" href="javascript:batchPrint();"><i class="mrs img btnPrint"></i><span class="uiButtonText">批量打印</span></a>
								<a class="uiButton uiButtonSpecial" href="javascript:batchExport();"><i class="mrs img btnDownload"></i><span class="uiButtonText">导出调查问卷结果</span></a>
							</div>
						</cfif>
				
						<h3>近一个月完成的调查问卷</h3>
						<p><span class="img icon16x16 message"></span>截至目前, 在本月已经完成调查数据收集的问卷, 在这里您可以查看问卷的数据最终收集状况.</p>
					</div>
					
					<cfif rs_questRecentMonth.recordCount>

							<cfset row = 0 />
							<table id="tableRecentVote" class="UIEditable">
								<thead>
									<tr>
										<td width="18"><a href="javascript:void(0);" class="stat no qsnall"></a></td>
										<td>问卷</td>
										<td>发布人</td>
										<td width="90">起止时间</td>
										<td width="40">回执</td>
										<td width="40">预计</td>
										<td width="18"></td>
									</tr>
								</thead>
								<tbody>
                                    <cfloop query="rs_questRecentMonth">
										<cfset row++ />
										<cfset structInsert( passArgs, "QSN", rs_questRecentMonth.qsn_id, true ) />
								
										<tr class="editRows">
											<td><a href="javascript:void(0);" class="stat no qsntrigger" rowid="<cfoutput>#rs_questRecentMonth.qsn_id#</cfoutput>"></a></td>
											<td><cfoutput>#rs_questRecentMonth.title#</cfoutput></td>
											<td><cfoutput>#rs_questRecentMonth.tch_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#dateTimeAdvice.formatDateString( rs_questRecentMonth.date_start, 'MM/DD' )#</cfoutput> - <cfoutput>#dateTimeAdvice.formatDateString( rs_questRecentMonth.date_end, 'MM/DD' )#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_questRecentMonth.countRes_S#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_questRecentMonth.countRes#</cfoutput></span></td>
											<td><a href="<cfoutput>#buildURL('voteDetail', passArgs)#</cfoutput>" class="stat details"></a></td>
										</tr>
									
									</cfloop>
									<cfset structDelete( passArgs, "QSN", false ) />
								</tbody>
							</table>
					
							<script language="javascript" type="text/javascript">
								//<![CDATA[
								<!--

								function batchPrint() {
						
									var qsnIds = [];
							
									$("#tableRecentVote a.qsntrigger.yes").each(function(index, element) {
										qsnIds.push( $(this).attr("rowid") );
									});
							
									if (qsnIds.length) {
										$("#printQSNIDs").val( qsnIds.join() );
										/* 提交打印请求 */
										$("#formPrint").submit();
									}
									else {
										alert("请至少选择一个问卷");
									}

								}
						
								function batchExport() {
							
									var qsnIds = [];
							
									$("#tableRecentVote a.qsntrigger.yes").each(function(index, element) {
										qsnIds.push( $(this).attr("rowid") );
									});
							
									if (qsnIds.length) {
										$("#exportQSNIDs").val( qsnIds.join() );
										/* 提交导出请求 */
										$("#formExport").submit();
									}
									else {
										alert("请至少选择一个问卷");
									}
							
								}
						
								$(document).ready(function() {
							
									$("#tableRecentVote a.qsnall").click(function(){
								
										var $trigger = $(this);
								
										var status = $trigger.hasClass("yes");
										var newStatus = true;
								
										/* 切换状态数据 */
										if (status) {
											newStatus = false;
										}
								
										if ( newStatus ) { 
									
											$("#tableRecentVote a.qsntrigger").removeClass("no").addClass("yes");
									
											$trigger.removeClass("no").addClass("yes");
										} 
										else { 
								
											$("#tableRecentVote a.qsntrigger").removeClass("yes").addClass("no"); 
									
											$trigger.removeClass("yes").addClass("no"); 
										}
								
								
									});

									$("#tableRecentVote a.qsntrigger").click(function(){
								
										var $trigger = $(this);
								
										var status = $trigger.hasClass("yes");
										var newStatus = true;
								
										/* 切换状态数据 */
										if (status) {
											newStatus = false;
										}
								
										if ( newStatus ) { 
											$trigger.removeClass("no").addClass("yes");
										} 
										else { 
											$trigger.removeClass("yes").addClass("no"); 
										}
								
									});
							
								});
								// -->
								//]]>				
							</script>
						
						<cfelse>
							
							<div class="systemNotice">
								<h3>没有已完成的问卷</h3>
							</div>
							
					</cfif>
					
				</div>
			
			</div>
		</li>
	</ul>
</div>